package main

import (
	"fmt"
	"time"
)

func send(ch chan int, msg int) {
	ch <- msg
	fmt.Printf("Send %d\n", msg)
}

func receive(ch chan int) {
	msg := <-ch
	fmt.Printf("Receive %d\n", msg)
}

func main() {
	// write block
	fmt.Println("Channel 1")
	ch1 := make(chan int, 3)
	for i := 0; i < 5; i++ {
		go send(ch1, i)
	}
	time.Sleep(2 * time.Second)
	for i := 0; i < 2; i++ {
		receive(ch1)
	}
	time.Sleep(2 * time.Second)
	fmt.Println()
	// read block
	fmt.Println("Channel 2")
	ch2 := make(chan int, 3)
	for i := 0; i < 5; i++ {
		go receive(ch2)
	}
	time.Sleep(2 * time.Second)
	for i := 0; i < 3; i++ {
		send(ch2, i)
	}
	time.Sleep(2 * time.Second)
}
